﻿<%@ Page Title="Мой профиль" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ViewProfile.aspx.cs" Inherits="Matrix_network.MyProfile" %>
<asp:Content ID="HeaderContent" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="PageHeaderContent" ContentPlaceHolderID="PageHeaderContent" runat="server">
    <asp:Label runat="server" Text="<%$ Resources: MyProfile %>" />
</asp:Content>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
    <% if (RedirectRequired) { %>
    <script type="text/javascript">location.href = '';</script>
    <% } %>
    <div class="photo float">
        <% if (ViewingUser.ava_id != null) { %>
        <p><img src="/Photo/<%= ViewingUser.ava_id %>" width="250" alt="" /></p>
        <% } else { %>
        <p><img src="/Images/no_avatar.png" width="250" alt="" /></p>      
        <% }
           if (IsCurrentUser) { %>
        <p><span class="link" onclick="javascript:$('.uploadPhoto').fadeIn();"><asp:Literal runat="server" Text="<%$ Resources: Change %>" /></span></p>
        <div class="uploadPhoto">
            <p class="red">
                <asp:RequiredFieldValidator ID="photoRequiredValidator" runat="server" ValidationGroup="UploadPhoto" ControlToValidate="photo" ErrorMessage="<%$ Resources: PhotoRequired %>" Display="Dynamic" />
                <asp:RegularExpressionValidator ID="photoExtensionValidator" runat="server" ValidationGroup="UploadPhoto" ControlToValidate="photo" 
                    ErrorMessage="<%$ Resources: AllowOnlyJpg %>"
                    ValidationExpression=".+\.(jpg)|(JPG)|(jpeg)|(JPEG)$" Display="Dynamic" />
            </p>
            <div>
                <asp:Literal runat="server" Text="<%$ Resources: PhotoJpg %>" /><br />
                <asp:FileUpload runat="server" ValidationGroup="UploadPhoto" ID="photo" />
            </div>
            <div class="formLine">
                <asp:Button runat="server" Text="<%$ Resources: OK %>" ValidationGroup="UploadPhoto" style="width: 100px;" OnClick="UploadPhoto_Click"/>
                <input type="button" value="<asp:Literal runat="server" Text="<%$ Resources: Cancel%>" />" style="width: 100px;" onclick="javascript:$('.uploadPhoto').fadeOut();"/>
            </div>
        </div>
        <% } %>
    </div>
    
    <div class="profile float">
        <h2 class="username"><%= ViewingUser.name %> <%= ViewingUser.surname %></h2>
        <% if (IsCurrentUser) { %>
        <p><span class="link" onclick="javascript:$('.changeUsername').fadeIn();"><asp:Literal runat="server" Text="<%$ Resources: Change %>" /></span></p>
        <div class="changeUsername">
            <p class="red">
                <asp:RequiredFieldValidator ID="fnameRequiredValidator" runat="server"
                    ControlToValidate="fname" ErrorMessage="<%$ Resources: FNameRequired %>" ValidationGroup="ChangeUsername" Display="Dynamic" />
                <asp:RequiredFieldValidator ID="lnameRequiredValidator" runat="server"
                    ControlToValidate="lname" ErrorMessage="<%$ Resources: LNameRequired %>" ValidationGroup="ChangeUsername" Display="Dynamic" />
            </p>
            <div class="formLine">
                <div class="label"><asp:Literal runat="server" Text="<%$ Resources: FName %>" /></div>
                <div class="input">
                    <asp:TextBox runat="server" ID="fname"/>
                </div>
            </div>
            <div class="formLine">
                <div class="label"><asp:Literal runat="server" Text="<%$ Resources: LName %>" /></div>
                <div class="input">
                    <asp:TextBox runat="server" ID="lname"/>
                </div>
            </div>
            <div class="formLine">
                <asp:Button runat="server" Text="<%$ Resources: OK %>" ValidationGroup="ChangeUsername" style="width: 100px;" OnClick="EditUsername_Click"/>
                <input type="button" value="<asp:Literal runat="server" Text="<%$ Resources: Cancel%>" />" style="width: 100px;" onclick="javascript:$('.changeUsername').fadeOut();"/>
            </div>
        </div>
        <% } %>

        <h2 class="aboutUser"><asp:Literal runat="server" Text="<%$ Resources: About %>" /></h2>
        <asp:ObjectDataSource runat="server" ID="aboutUserData" TypeName="Matrix_network.AboutUserDataSource"
        SelectMethod="Select" UpdateMethod="Update" DeleteMethod="Delete" InsertMethod="Insert">
            <UpdateParameters>
                <asp:ControlParameter Name="id" ControlID="gridAboutUser" />
                <asp:FormParameter Name="name" FormField="name" />
                <asp:FormParameter Name="val" FormField="val" />
            </UpdateParameters>
            <DeleteParameters>
                <asp:ControlParameter Name="id" ControlID="gridAboutUser" />
            </DeleteParameters>
        </asp:ObjectDataSource>
        <% if (IsCurrentUser) { %>
        <asp:GridView CssClass="aboutUser" runat="server" ID="gridAboutCurrentUser" DataSourceID="aboutUserData" DataKeyNames="id" ShowHeader="False" AutoGenerateColumns="False">
            <Columns>
                <asp:BoundField DataField="name" />
                <asp:BoundField DataField="val" />
                <asp:CommandField ShowEditButton="True" ShowDeleteButton="True"
                    EditText="<%$ Resources: Change %>" DeleteText="<%$ Resources: Delete %>" UpdateText="<%$ Resources: Update %>" CancelText="<%$ Resources: Cancel %>"/>
            </Columns>
        </asp:GridView>
        <% } else { %>
        <asp:GridView CssClass="aboutUser" runat="server" ID="gridAboutUser" DataSourceID="aboutUserData" DataKeyNames="id" ShowHeader="False" AutoGenerateColumns="False">
            <Columns>
                <asp:BoundField DataField="name" />
                <asp:BoundField DataField="val" />
            </Columns>
        </asp:GridView>
        <% }
            if (IsCurrentUser)
            { %>
        <p><span class="link" onclick="javascript:$('.newProperty').fadeIn();"><asp:Literal runat="server" Text="<%$ Resources: Add %>" /></span></p>
        <p class="red">
            <asp:RequiredFieldValidator ID="nameRequiredValidator" runat="server"
                ControlToValidate="propertyName" ErrorMessage="<%$ Resources: PropertyNameRequired %>" ValidationGroup="NewProperty" Display="Dynamic" />
            <asp:RequiredFieldValidator ID="valueRequiredValidator" runat="server"
                ControlToValidate="propertyValue" ErrorMessage="<%$ Resources: PropertyValueRequired %>" ValidationGroup="NewProperty" Display="Dynamic" />
            <asp:CustomValidator ID="nameUniqueValidator" runat="server" OnServerValidate="CheckUniquePropertyName"
                ErrorMessage="<%$ Resources: NameAlreadyExists %>" ValidationGroup="NewProperty" Display="Dynamic" />
        </p>
        <div class="newProperty">
            <div class="formLine">
                <div class="label"><asp:Literal runat="server" Text="<%$ Resources: Name %>" /></div>
                <div class="input">
                    <asp:TextBox runat="server" ID="propertyName"/>
                </div>
            </div>
            <div class="formLine">
                <div class="label"><asp:Literal runat="server" Text="<%$ Resources: Value %>" /></div>
                <div class="input">
                    <asp:TextBox runat="server" ID="propertyValue"/>
                </div>
            </div>
            <div class="formLine">
                <asp:Button runat="server" ValidationGroup="NewProperty" Text="<%$ Resources: OK %>" style="width: 100px;" OnClick="NewProperty_Click"/>
                <input type="button" value="<asp:Literal runat="server" Text="<%$ Resources: Cancel%>" />" style="width: 100px;" onclick="javascript:$('.newProperty').fadeOut();"/>
            </div>
        </div>
        <% } else { %>
        <p>
            <% if (IsCurrentUserFriend) { %>
            <asp:LinkButton runat="server" OnClick="RemoveFriend_Click"><asp:Literal runat="server" Text="<%$ Resources: DeleteFriend %>" /></asp:LinkButton>
            <% } else { %>
            <asp:LinkButton runat="server" OnClick="AddFriend_Click"><asp:Literal runat="server" Text="<%$ Resources: AddFriend %>" /></asp:LinkButton>
            <% } %>
            <a href="/SendMessage.aspx?toId=<%= ViewingUser.id %>" style="margin-left: 20px;"><asp:Literal runat="server" Text="<%$ Resources: SendMessage %>" /></a>
        </p>
        <% } %>
    </div>
</asp:Content>
